package com.bcn.login_mybatisplus_demo.diary.controller;

import java.util.List;

import com.bcn.login_mybatisplus_demo.common.controller.BaseController;
import com.bcn.login_mybatisplus_demo.common.page.TableDataInfo;
import com.bcn.login_mybatisplus_demo.diary.domain.TAppDiary;
import com.bcn.login_mybatisplus_demo.diary.service.ITAppDiaryService;
import com.bcn.login_mybatisplus_demo.pojo.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 心岛日志Controller
 * 
 * @author administrator
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/system/diary")
public class TAppDiaryController extends BaseController
{
    private String prefix = "system/diary";

    @Autowired
    private ITAppDiaryService tAppDiaryService;

    @GetMapping()
    public String diary()
    {
        return prefix + "/diary";
    }

    /**
     * 查询心岛日志列表
     */
    @GetMapping("/list")
    public TableDataInfo list( TAppDiary tAppDiary)
    {
        startPage();
        List<TAppDiary> list = tAppDiaryService.selectTAppDiaryList(tAppDiary);
        return getDataTable(list);
    }



    /**
     * 新增心岛日志
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存心岛日志
     */
    @PostMapping("/add")
    public R addSave(@RequestBody  TAppDiary tAppDiary)
    {
        return R.success(tAppDiaryService.insertTAppDiary(tAppDiary));
    }

    /**
     * 修改心岛日志
     */
    @GetMapping("/edit/{diaryId}")
    public String edit(@PathVariable("diaryId") Integer diaryId, ModelMap mmap)
    {
        TAppDiary tAppDiary = tAppDiaryService.selectTAppDiaryById(diaryId);
        mmap.put("tAppDiary", tAppDiary);
        return prefix + "/edit";
    }

    /**
     * 修改保存心岛日志
     */
    @PostMapping("/edit")
    public R editSave(@RequestBody  TAppDiary tAppDiary)
    {
        return R.success(tAppDiaryService.updateTAppDiary(tAppDiary));
    }

    /**
     * 删除心岛日志
     */
    @GetMapping( "/remove/{id}")
    public R remove(@PathVariable("id") Integer id)
    {
        return R.success(tAppDiaryService.deleteTAppDiaryById(id));
    }
}
